{#include file="top.php"#}
<link rel="stylesheet" href="/css/jquery.Jcrop.css" type="text/css" />
<script src="/js/jquery.Jcrop.js"></script>
<div class="body">
    <div class="main">
        <form id="register_form" enctype="multipart/form-data" action="member.php?action=MyProfile" method="POST">

            <div class="basic_info b_box">
                <div class="hd">
                    <h2 class="hd_title">基本資料</h2>
                </div>
                <div class="bd">
                    <div class="basic_info_box basic_info_box_last">

                        <p>
                            會員名：{#$member.username#}
                        </p>
                        <p class="name_p">
                            原密碼({#$OLDPASSWORD#})
                        </p>
                        <input type="password" class="info_ipt_text" id="opassword" name="opassword"value=""/>

                        <a href="###" onclick="$('#showpw').toggle()" class="pink">修改密碼</a>

                        <div id=showpw style="display:none">
                            <p class="name_p">
                                新密碼
                            </p>
                            <input type="password" class="info_ipt_text" id="password" name="password" value=""/>
                            <p style="display:none;"  id="password_tip">
                                <em class="hack"></em>
                                <a class="close"> <span></span> </a>
                                <span id="password_tip_text">{#$ERR_PWD#}</span>
                            </p>
                            <p class="name_p">
                                確認新密碼
                            </p>
                            <input type="password" class="info_ipt_text" id="cpassword" name="cpassword"  value=""/>
                            <p style="display:none;"  id="cpassword_tip">
                                <em class="hack"></em>
                                <a class="close"> <span></span> </a>
                                <span id="cpassword_tip_text">{#$ERR_CPWD#}</span>
                            </p>
                        </div>

                        <p class="name_p">
                            電郵地址（{#$CHANGEEMAIL#}） <a href="{#$selfurl#}?action=resendActivation">重發激活郵件</a>
                        </p>
                        <input type="text" class="info_ipt_text" id="email" name="email"  value="{#$member.email#}" />
                        <p style="display:none;"  id="email_tip">
                            <em class="hack"></em>
                            <a class="close"> <span></span> </a>
                            <span id="email_tip_text">{#$ERR_EMAIL#}</span>
                        </p>
                        <p class="name_p">
                            英文名字
                        </p>
                        <input type="text" class="info_ipt_text" id="ename" value="{#$member.ename#}" name="reg_p[ename]" />
                        <p class="tip"  style="display:none;" id="ename_tip" >
                            <em class="hack"></em>
                            <a class="close" > </a>
                            <span id="ename_tip_text">請輸入英文名字</span>
                        </p>
                        <p class="name_p">
                            香港身份証號碼
                        </p>
                        <input type="text" class="info_ipt_text" id="idcard" maxlength="4" name="reg_p[idcard]"  value="{#$member.idcard#}"/>
                        <p style="display:none;"  id="idcard_tip">
                            <em class="hack"></em>
                            <a class="close"> <span></span> </a>
                            <span id="idcard_tip_text">{#php#}echo ERR_IDCAR;{#/php#}</span>
                        </p>
                        <p class="name_p">
                            性別
                        </p>
                        <span class="option"><input type="radio" value="1" name="reg_p[sex]" {#if $member.sex==1#}checked="checked"{#/if#}>男.</span>
                        <span class="option"><input type="radio" value="2" name="reg_p[sex]" {#if $member.sex==2#}checked="checked"{#/if#}>女</span>

                        <p class="name_p">
                            手提電話號碼
                        </p>
                        <input type="text" class="info_ipt_text" maxlength="11" id="phone" name="reg_p[phone]"  value="{#$member.phone#}"/>
                        <p style="display:none;"  id="phone_tip">
                            <em class="hack"></em>
                            <a class="close"> <span></span> </a>
                            <span id="phone_tip_text">{#php#}echo ERR_PHONE;{#/php#}</span>
                        </p>
                        <p class="name_p">
                            出生日期
                        </p>
                        <input type="text" class="info_ipt_text" id="birthday" name="reg_p[birthday]" value="{#$member.birthday#}"/>
                        <p style="display:none;"  id="birthday_tip">
                            <em class="hack"></em>
                            <a class="close"> <span></span> </a>
                            <span id="birthday_tip_text">{#php#}echo ERR_BIRTH;{#/php#}</span>
                        </p>
                        <div class="filebox">
                            <div class="img_box_r" >
                                <img src="{#$member.photo#}"  width=84 height="84"  id="preview_pic">
                            </div>
                            <a class="btn_s btn_s_upload_a" href="javascript:void(0);" onclick="show_upload_pic()"> <strong>選擇檔案</strong></a>
                            <input type="hidden" id="avatar" name="photo">
                            <input type="hidden" id="x" name="x" />
                            <input type="hidden" id="y" name="y" />
                            <input type="hidden" id="w" name="w" />
                            <input type="hidden" id="h" name="h" />

                        </div>

                    </div>
                    <div class="other_login">

                        <em class="hack"></em>
                        {#if !$session.facebook.id#}{#else#}<a href="###" class="fbtn"><strong>綁定facebook</strong></a><p>已綁定facebook<br>{#$session.email#}</p>{#/if#}


                    </div>
                </div>
            </div>

            <div class="try_daren b_box">
                <div class="hd">
                    <h2 class="hd_title">試用達人</h2>
                </div>
                <div class="bd">
                    <table border="0" cellspacing="0" cellpadding="0" class="try_tb">


                        <tr>
                            <th>行業<span class="span_pink" >*</span>：</th><td>
                                <select class="try_select" id='profession' name='profession'  onclick="$('#profession_err').hide();">

                                    {#foreach from=$layout.profession item=v key=k#}
                                    <option  {#if $layout.member.profession==$v.id#}selected{#/if#}  value='{#$v.id#}'>{#$v.cname#}</option>
                                    {#/foreach#}
                                </select></td>
                        </tr>
                        <tr>
                            <th></th><td><p class="tip" id="profession_err" style="display:none;">
                                    <em class="hack"></em>
                                    <a class="close" href="#"> close </a>
                                    <span id="profession_err_text">{#$HAS_PROFESSION#}</span>
                                </p></td>
                        </tr>
                        <tr>
                            <th>身型<span class="span_pink">*</span>：</th><td>
                                <select class="try_select" id='body' name='body'  onclick="$('#body_err').hide();">

                                    {#foreach from=$layout.body item=v key=k#}
                                    <option  {#if $layout.member.body==$v.id#}selected{#/if#}   value='{#$v.id#}'>{#$v.cname#}</option>
                                    {#/foreach#}
                                </select></td>
                        </tr>
                        <tr>
                            <th></th><td><p class="tip" id="body_err" style="display:none;">
                                    <em class="hack"></em>
                                    <a class="close" href="#"> close </a>
                                    <span id="body_err_text">{#$HAS_BODY#}</span>
                                </p></td>
                        </tr>
                        <tr>
                            <th>臉部膚質<span class="span_pink">*</span>：</th><td>
                                <select class="try_select" id='face_skin' name='face_skin'  onclick="$('#face_skin_err').hide();">

                                    {#foreach from=$layout.face_skin item=v key=k#}
                                    <option  {#if $layout.member.face_skin==$v.id#}selected{#/if#}  value='{#$v.id#}'>{#$v.cname#}</option>
                                    {#/foreach#}
                                </select></td>
                        </tr>
                        <tr>
                            <th></th><td><p class="tip" id="face_skin_err" style="display:none;">
                                    <em class="hack"></em>
                                    <a class="close" href="#"> close </a>
                                    <span id="face_skin_err_text">{#$HAS_FACE_SKIN#}</span>
                                </p></td>
                        </tr>
                        <tr>
                            <th>身體膚質<span class="span_pink">*</span>：</th><td>
                                <select class="try_select" id='body_skin' name='body_skin'  onclick="$('#body_skin_err').hide();">
                                    {#foreach from=$layout.body_skin item=v key=k#}
                                    <option  {#if $layout.member.body_skin==$v.id#}selected{#/if#}  value='{#$v.id#}'>{#$v.cname#}</option>
                                    {#/foreach#}
                                </select></td>
                        </tr>
                        <tr>
                            <th></th><td><p class="tip" id="body_skin_err" style="display:none;">
                                    <em class="hack"></em>
                                    <a class="close" href="#"> close </a>
                                    <span id="body_skin_err_text">{#$HAS_BODY_SKIN#}</span>
                                </p></td>
                        </tr>
                        <tr>
                            <th>髮質<span class="span_pink">*</span>：</th><td>
                                <select class="try_select" id='hair' name='hair' onclick="$('#hair_err').hide();">

                                    {#foreach from=$layout.hair item=v key=k#}
                                    <option  {#if $layout.member.hair==$v.id#}selected{#/if#}  value='{#$v.id#}'>{#$v.cname#}</option>
                                    {#/foreach#}
                                </select></td>
                        </tr>
                        <tr>
                            <th></th><td><p class="tip" id="hair_err" style="display:none;">
                                    <em class="hack"></em>
                                    <a class="close" href="#"> close </a>
                                    <span id="hair_err_text">{#$HAS_HAIR#}</span>
                                </p></td>
                        </tr>

                        <tr><th class="address">
                                郵寄地址<span class="span_pink">*</span>：</div>
                            <td><textarea class="daren_textarea" rows="8" cols="40" name="address" id="address"  onclick="$('#address_err').hide();" onchange="$('#address_err').hide();" onblur="$('#address_err').hide();" onkeydown="$('#address_err').hide();">{#$layout.member.address#}</textarea>
                                (星期一至五辦公時間內，有效簽收產品之中文商業地址)
                            </td>
                        </tr>
                        <tr>
                            <th></th><td><p class="tip" id="address_err" style="display:none;">
                                    <em class="hack"></em>
                                    <a class="close" href="#"> close </a>
                                    <span id="address_err_text">{#$HAS_ADDRESS#}</span>
                                </p></td>
                        </tr>
                    </table>
                </div>
            </div>

            <div class="exp_team b_box">
                <div class="hd">
                    <h2 class="hd_title">體驗達人</h2>
                </div>
                <div class="bd">
                    <table border="0" cellspacing="0" cellpadding="0" class="try_tb">


                        <tr>
                            <th>網誌連結<span class="span_pink">*</span>：</th></th><td>
                                <input class="try_ipt_text" onclick="$('#homepage_err').hide();" onchange="$('#homepage_err').hide();" onblur="$('#homepage_err').hide();" onkeydown="$('#homepage_err').hide();" name="homepage" id="homepage" value="{#$layout.member.homepage#}" />
                        </tr><tr><th></th><td>只要簡單幾個步驟，即可批核成為體驗達人，盡享星級產品體驗。
                                <br>
                                第 1 步： 請於個人美容部落格發一篇名為「我要成為 iTrial 體驗達人」的文章，並在文章內輸入以下驗証碼
                                <br>
                                第 2 步：請提供該篇網誌之連結然後發送
                                <br>

                                驗證碼：{#$layout.member.code#}<br><br></td></tr>
                        <tr>
                            <th></th><td><p class="tip" id="homepage_err" style="display:none;">
                                    <em class="hack"></em>
                                    <a class="close"> close </a>
                                    {#$HAS_HOMEPAGE#}
                                </p></td>
                        </tr>
                        <!--
                                                <tr>
                                                    <th>快速審核驗證：</th><td>
                                                        <input type="text" class="try_ipt_text"  name="blogPage" value="{#$layout.member.blogPage#}" />
                                                </tr>
                                                <tr>
                                                    <th></th><td>
                                                        <p class="tip">
                                                            <em class="hack"></em>
                                                            <a class="close" href="#"> close </a>
                                                            請於個人部落格內發表一篇包含此驗証碼 {#$layout.member.code#} 之文章，代表閣下擁有該部落客。
                                                        </p></td>
                                                </tr>
                        -->
                        <tr>
                            <th>試用評鑑報告：</th><td>
                                <input type="text" class="try_ipt_text" name="reportURL" value="{#$layout.member.reportURL#}"/>
                        </tr>
                        <tr>
                            <th></th><td>
                                <p class="tip">
                                    <em class="hack"></em>
                                    <!--<a class="close" href="#"> close </a>-->
                                    請提供閣下曾於「試用專區」內填寫之試用評鑑報告連結，提高成功被審核機會。
                                </p></td>
                        </tr>

                        <tr>
                            <th>最喜愛的美容品牌<span class="span_pink">*</span>：</th><td>
                                <a class="experience_group_slt" href="###" onclick="toggle_brand_form();$('#brand_err').hide();" id="brand_a">Please Select</a>
                            </td>
                        </tr>
                        <tr>
                            <th></th><td><p class="tip" id="brand_err" style="display:none;">
                                    <em class="hack"></em>
                                    <a class="close"> close </a>
                                    {#$HAS_BRAND#}
                                </p></td>
                        </tr>
                        <tr>
                            <th>最關注皮膚問題<span class="span_pink">*</span>：</th><td>
                                <ul class="option_list">
                                    {#foreach from=$layout.question item=value key=key#}
                                    <li class="option"><input type="checkbox" name="question[]" {#if in_array($value.id,$layout.member.question)#}checked="checked"{#/if#} onclick="$('#question_err').hide();"  value="{#$value.id#}">{#$value.cname#} </li>
                                    {#/foreach#}
                                </ul></td>
                        </tr>
                        <tr>
                            <th></th><td><p class="tip" id="question_err" style="display:none;">
                                    <em class="hack"></em>
                                    <a class="close"> close </a>
                                    {#$HAS_QUESTION#}
                                </p></td>
                        </tr>
                        <tr>
                            <th>個人興趣<span class="span_pink">*</span>：</th><td>
                                <ul class="option_list">
                                    {#foreach from=$layout.interest item=value key=key#}
                                    <li class="option"><input type="checkbox" name="interest[]"   {#if in_array($value.id,$layout.member.interest)#}checked="checked"{#/if#}  onclick="$('#interest_err').hide();"  value="{#$value.id#}">{#$value.cname#} </li>
                                    {#/foreach#}
                                </ul></td>
                        </tr>
                        <tr>
                            <th></th><td><p class="tip"  id="interest_err" style="display:none;">
                                    <em class="hack"></em>
                                    <a class="close"> close </a>
                                    {#$HAS_INTEREST#}
                                </p></td>
                        </tr>
                        <tr>
                            <th>個人半身近照<span class="span_pink">*</span>：</th><td class="upload_td">
                                <div class="filebox">
                                    <div class="img_box" id="avatar2_thumbnail">
                                        <img src="{#if $layout.member.photo#}{#$layout.member.photo#}{#else#}data/p84x84.jpg{#/if#}" width=84 height="84">
                                    </div>
                                    <a class="btn_s btn_s_upload sfile" style="cursor:pointer"> <strong>選擇檔案</strong><input type="file" class="file_upload" id="avatar2_file" style="cursor:pointer"></a>

                                    <input type="hidden" id="avatar2" name="photo2" value="{#$layout.member.photo#}">

                                </div></td>
                        </tr>
                        <tr>
                            <th></th><td>
                                <p class="tip" style="display:none;"  id="avatar2_file_tip">
                                    <em class="hack"></em>
                                    <a class="close"> close </a>
                                    <span id="avatar2_file_tip_text"><span id="avatar2_file_tip_text">{#$HAS_INVITE_PIC#}</span>
                                </p></td>
                        </tr>
                    </table>

                </div>

                <div class="ft">


                    <input type="checkbox" class="checkbox" id="email_receive" name="reg_p[email_receive]" value="1" {#if $session.email_receive==1#}checked="checked" {#/if#}> 我願意收到iMORE及新傳媒集團最新消息及其他宣傳資訊的電子郵件。</p>
                </div>

                <input type="hidden" name="issubmit" value="1" />
                <input type="hidden" name="brand_val" value="{#implode(',',$layout.member.brand)#}" id="brand_a_val" />
                <a href="###" class="btn_s btn_s_complete" onclick="submit_form();"><strong>完成</strong></a>
            </div>

        </form>
    </div><!-- main-->
    <div class="sidebar">
        {#show_block('b2',1,'','sidebar_ad')#}
        {#show_block('b1',2,'','sidebar_function')#}
        {#show_block('b3',0,'','sidebar_search')#}
        {#show_block('b4',0,'','sidebar_workshop')#}
        {#show_block('b5',0,'','sidebar_top3 b_box')#}
    </div>
    <!-- sidebar -->

</div><!--body-->
<div class="popup popup_3" id="upload_photo" style="visibility:hidden;">
    <a class="btn_close" href="###" onclick="hide_upload_pic()"></a>
    <div class="avatar_box b_box">
        <div class="hd">
            <h2 class="hd_title">上傳頭像</h2>
        </div>
        <div class="bd">
            <div class="img_box_l">
                <img id="cropbox" src="images/400x400.jpg" alt="" width="400"  />
            </div>
            <div class="img_box_r" >
                <img id="preview" src="images/400x400.jpg" alt="" width=84 height="84"  />
            </div>
            <a class="btn_s btn_s_upload" href="###"><strong>選擇檔案</strong>
                <input type="file" class="file_upload"  id="avatar_file" >
            </a>
            <a class="btn_s btn_s_sure" href="###" onclick="hide_upload_pic()"><strong>確定</strong></a>
        </div>
    </div>
</div>
<link rel="stylesheet" href="js/ui/jquery-ui-1.8.8.custom.css">
<script src="js/ui/jquery-ui-1.8.8.custom.min.js"></script>

<script>
    // Remember to invoke within jQuery(window).load(...)
    // If you don't, Jcrop may not initialize properly
    

    // Our simple event handler, called from onChange and onSelect
    // event handlers, as per the Jcrop invocation above
    function showPreview(coords)
    {
        if (parseInt(coords.w) > 0)
        {
            var rx = 84 / coords.w;
            var ry = 84 / coords.h;

            jQuery('#preview').css({
                width: Math.round(rx * 400) + 'px',
                height: Math.round(ry * 400) + 'px',
                marginLeft: '-' + Math.round(rx * coords.x) + 'px',
                marginTop: '-' + Math.round(ry * coords.y) + 'px'
            });
            jQuery('#preview_pic').css({
                width: Math.round(rx * 400) + 'px',
                height: Math.round(ry * 400) + 'px',
                marginLeft: '-' + Math.round(rx * coords.x) + 'px',
                marginTop: '-' + Math.round(ry * coords.y) + 'px'
            });
        }
    }
    function updateCoords(c)
    {
        $('#x').val(c.x);
        $('#y').val(c.y);
        $('#w').val(c.w);
        $('#h').val(c.h);
    };
    
    function show_upload_pic(){
        $('#upload_photo').attr("style","visibility:visible;");
    }
    function hide_upload_pic(){
        $('#upload_photo').attr("style","visibility:hidden;");
    }
    
    var click_brand=0;
    function selectcheckbox(aid,divid){
        var selectvar="";
        var brandselect = "";
        var productsbrandsnum=0;

        $("#"+divid).attr("style","visibility:hidden;");
        click_brand = 0;

        $("#"+divid+" input").each(function(i){
            if($(this).attr("checked")==true && $(this).attr("disabled")!=true){
                productsbrandsnum+=1;
                selectvar+=$(this).attr("brand_name")+",";
                brandselect+=$(this).val()+",";
                
            }
        });
        if(productsbrandsnum>0){
            selectvar=selectvar.substring(0,selectvar.length-1);
            brandselect=brandselect.substring(0,brandselect.length-1);
            $("#"+aid).html(selectvar);
            $("#"+aid+'_val').val(brandselect);
        }else{
            $("#"+aid).html("Please Select");
        }
    }
    function toggle_brand_form(){
        if(click_brand==0){
            $("#brand_form").attr("style","visibility:visible;top: 1380px;");            
            click_brand = 1;
        }else{
            $("#brand_form").attr("style","visibility:hidden;top: 1380px;");
            selectcheckbox('brand_a','brand_form');
            click_brand = 0;
        }
        
        
    }
</script>
<script>
    $.ajaxSetup({
        async : false
    });
    (function($){
        $.fn.imgIframeUpload = function(settings) {

            var form;
            var iframe;
            var	self = this;
            var	selfId = self.attr('id');
            var	opts = {
                action: "{#$selfurl#}?action=ajax_uploadAvatar",
                callback: null
            };
            $.extend(opts, settings);

            form = $('<form method="post" action="' + opts.action + '" enctype="multipart/form-data" target="iframe-upload-' + selfId + '" style="display:none;"><input type="hidden" name="old_temp" /><input type="hidden" name="callback_script" value="' + (opts.callback ? ('parent.' + opts.callback + '($res);') : '') + '" /></form>');
            iframe = $('<iframe name="iframe-upload-' + selfId + '" frameborder="0" style="display:none;" src="about:blank"></iframe>');
            $('body').append(form).append(iframe);

            function fileChange(obj){
                obj.change(function(){
                    var fileInputClone = $(this).clone().val('').hide();
                    $(this).after(fileInputClone).attr('name', 'temp[]').removeAttr('id').appendTo(form);
                    fileInputClone.css('display', 'inline');
                    fileChange(fileInputClone);
                    form.submit();
                    $(this).remove();
                });
            }

            fileChange(self);

        }
    })(jQuery);

    function upAvatarCallback(res){
        if(res){
            if(res[0].code == 1){
                $('#avatar').val(res[0].src);
                $('#cropbox').attr('src',res[0].thumb);
                $('#preview').attr('src',res[0].thumb);
                $('#preview_pic').attr('src',res[0].thumb);
                
                $(".jcrop-holder").find("img").attr('src',res[0].thumb);
                
                jQuery('#cropbox').Jcrop({                    
                    onSelect: updateCoords,
                    onChange: showPreview,				
                    aspectRatio: 1
                });
                //check_register_avatar();
            }else{
                $("#avatar_file_tip").addClass("tip").show();
                $("#avatar_file_tip_text").html(res[0].msg);
            }
        }
        $(window).focus();
    }
    function upAvatarCallback2(res){
        if(res){
            if(res[0].code == 1){
                $('#avatar2').val(res[0].thumb);
                $('#avatar2_thumbnail').html('<img src="' + res[0].thumb + '" width=84 height="84" />');
                //check_register_avatar();
            }else{
                $("#avatar2_file_tip").addClass("tip").show();
                $("#avatar2_file_tip_text").html(res[0].msg);
            }
        }
        $(window).focus();
    }
    var usename_ok,password_ok,cpassword_ok,salutation_ok,email_ok,phone_ok,idcard_ok,birthday_ok,captcha_ok;
    $(document).ready(function(){

        $('#avatar_file').imgIframeUpload({
            callback: 'upAvatarCallback'
        });

        $('#avatar2_file').imgIframeUpload({
            callback: 'upAvatarCallback2'
        });

        $("#birthday").datepicker({
            changeMonth: true,
            changeYear: true,
            defaultDate: new Date(1990, 1 - 1, 1),
            dateFormat:'yy-mm-dd',
            minDate:new Date(1900, 1 - 1, 1),
            yearRange: '1900:2010'
            //showOn: "button",
            //buttonImage: "js/ui/images/calendar.gif",
            //buttonImageOnly: true
        });

        $('#password').mousedown(check_register_password);
        $('#password').change(check_register_password);


        $('#cpassword').mousedown(check_register_cpassword);
        $('#cpassword').change(check_register_cpassword);

        $('#email').mousedown(check_register_email);
        $('#email').change(check_register_email);

        $('#phone').mousedown(check_register_phone);
        $('#phone').change(check_register_phone);

        $('#idcard').mousedown(check_register_idcard);
        $('#idcard').change(check_register_idcard);

        $('#birthday').change(check_register_birthday);


    });

    function check_register_salutation(){
        var salutation = $("input[name='reg_p[salutation]']:checked").val();
        if(salutation==1 || salutation==2 || salutation==3){
            $("#salutation_tip").removeClass("wrong");
            //$('#salutation_tip').text('稱謂選擇正確');
            return 1;
        }else{
            $("#salutation_tip").addClass("wrong").show();
            $('#salutation_tip').text('{#$ERR_SALUTATION#}');
            return 0;
        }
    }

    function check_register_phone(){
        var rt = 0;
        var phone=$('#phone').val();
        //if(phone.length>0){
        if(phone.match(/^[0-9]{8,11}$/) == null){
            $("#phone_tip").addClass("tip").show();
            $("#phone_tip_text").html('{#$ERR_PHONE#}')
            //}else if(phone.length<8){
            //$("#phone_tip").addClass("tip").html('{#$ERR_PHONE#}').show();
        }else{
            if(phone == '{#$member.phone#}'){
                $("#phone_tip").removeClass("tip").hide();
                rt =  1;
            }else{

                $('#phone_tip').addClass("tip").show();
                $("#phone_tip_text").html('{#$CHECKING#}');

                $.get("member.php?action=ajax_checkPhone",{phone:phone,act:"check_phone"},function(data){
                    if(data == 1){
                        $("#phone_tip").removeClass("tip").hide();
                        rt =  1;
                    }else if(data == -1) {
                        //$("#phone_tip").addClass("tip").show();
                        $("#phone_tip_text").html('{#$ERR_PHONE#}')
                    }else if(data == -2) {
                        //$("#phone_tip").addClass("tip").show();
                        $("#phone_tip_text").html('{#$HAS_PHONE#}')
                    }
                });
            }

        }
        /*}else{
                        rt =  1;
                        $("#phone_tip").removeClass("tip").hide();
                }*/
        return rt;
    }

    function check_register_birthday(){
        var birthday=$('#birthday').val();
        if(birthday == ''){
            $("#birthday_tip").addClass("tip").show();
            return 0;
        }else{
            $("#birthday_tip").removeClass("tip").hide();
            return 1;
        }
    }

    function check_register_idcard(){
        var idcard=$('#idcard').val();
        if(idcard.match(/^[A-Z][0-9a-z][0-9]{2}$/i) == null){
            $("#idcard_tip").addClass("tip").show();
            return 0;
        }else{
            $("#idcard_tip").removeClass("tip").hide();
            return 1;
        }
    }

    function check_register_ename(){
        var ename=$('#ename').val();
        if(ename == ''){
            $("#ename_tip").addClass("tip").show();
            return 0;
        }else{
            $("#ename_tip").removeClass("tip").hide();
            return 1;
        }
    }


    function check_register_password(){
        var rt = 0;
        var password = $('#password').val();
        if(password){
            var opassword = $('#opassword').val();
            if(!opassword){
                $("#password_tip").addClass("tip").show();
                $("#password_tip_text").html('{#$HAS_OPASSWORD#}')
            }else{
                if(password.match(/^.{6,20}$/i) == null){
                    $("#password_tip").addClass("tip").show();
                    $("#password_tip_text").html('{#$ERR_PWD#}')
                }else{
                    $("#password_tip").removeClass("tip").hide();
                    rt =  1;
                }
            }
        }else{
            $("#password_tip").removeClass("tip").hide();
            rt =  1;
        }

        return rt;
    }

    function check_register_cpassword(){
        var rt = 0;
        var password = $('#password').val();
        var cpassword = $('#cpassword').val();
        if(cpassword != '' && password != cpassword){
            $("#cpassword_tip").addClass("tip").show();
            $("#cpassword_tip_text").html('{#$ERR_CPWD#}')
        }else if(password == cpassword){
            $("#cpassword_tip").removeClass("tip").hide();
            rt =  1;
        }
        return rt;
    }


    function check_register_email(){
        var rt = 0;
        var email=$.trim($('#email').val());
        if(email == '{#$member.email#}'){
            $("#email_tip").removeClass("tip").hide();
            rt =  1;
        }else{
            var opassword = $('#opassword').val();
            if(!opassword){
                $("#email_tip").addClass("tip").show();
                $("#email_tip_text").html('{#$HAS_OPASSWORD#}')
                $('#email').val('{#$session.email#}');
            }else{

                if(email.length>0){
                    $("#email_tip").addClass("tip").show();
                    $('#email_tip_text').text('{#$CHECKING#}');
                    $.get("member.php?action=ajax_checkEmail",{email:email},function(data){
                        if(data == -4){
                            $("#email_tip").addClass("tip").show();
                            $("#email_tip_text").html('{#$ERR_EMAIL#}')

                        }else if(data == -6) {
                            $("#email_tip").addClass("tip").show();
                            $("#email_tip_text").html('{#$HAS_EMAIL#}')

                        }else if(data == 1) {
                            $("#email_tip").removeClass("tip").hide();
                            rt =  1;
                        }
                    });
                }else{
                    $("#email_tip").addClass("tip").show();
                    $("#email_tip_text").html('{#$ERR_EMAIL#}')
                }
            }
        }


        return rt;
    }

    function check_register_avatar(){
        var rt = 0;
        if($('#avatar').val().length==0){
            $("#avatar_file_tip").addClass("tip").show();
            $("#avatar_file_tip_text").html('{#$HAS_INVITE_PIC#}')
        }else{
            $("#avatar_file_tip").removeClass("tip").hide();
            rt =  1;
        }
        return rt;
    }

    function check_register_avatar2(){
        var rt = 0;
        if($('#avatar2').val().length==0){
            $("#avatar2_file_tip").addClass("tip").show();
            $("#avatar2_file_tip_text").html('{#$HAS_INVITE_PIC#}')
        }else{
            $("#avatar2_file_tip").removeClass("tip").hide();
            rt =  1;
        }
        return rt;
    }

    function check_register_agree(){
        var rt = 0;
        if($("#agree").attr("checked")!=true){
            $("#agree_tip").addClass("tip").show();
            $("#agree_tip_text").html('{#$NO_AGREE#}')
        }else{
            $("#agree_tip").removeClass("tip").hide();
            rt =  1;
        }
        return rt;
    }

    function check_cssby(tipmainname){

        var obj =$("#"+tipmainname+"_tip");
        if(obj.attr('class')!='tip'){
            return 1;
        }else{
            return 0;
        }
    }
    function check_checkbox(name) {
        var falg = 0;
        $("input[name='"+name+"']:checkbox").each(function () {
            if ($(this).attr("checked")) {
                falg += 1;
            }
        });
        if (falg > 0) {
            return true;
        } else {
            return false;
        }
    }

    function reset_brand_checkbox(name){
        $("input[name='"+name+"']:checkbox").attr("checked",false);
    }

    function toggle_brand_checkbox(this_obj){
        if($(this_obj).parent().next('dl').css("display")=="none"){
            $(this_obj).parent().next('dl').show();
            $(this_obj).attr("class","few");
        }else{
            $(this_obj).parent().next('dl').hide();
            $(this_obj).attr("class","few plus");
        }
    }

    function submit_form(){

        var ck = {
            //'birthday'			:["{#$ERR_BIRTH#}",3],
            'profession'		:["{#$HAS_PROFESSION#}",1],
            'body'				:["{#$HAS_BODY#}",1],
            'face_skin'			:["{#$HAS_FACE_SKIN#}",1],
            'body_skin'			:["{#$HAS_BODY_SKIN#}",1],
            'hair'				:["{#$HAS_HAIR#}",1],
            //'phone'				:["{#$ERR_PHONE#}",3],
            'address'			:["{#$HAS_ADDRESS#}",3],
            'homepage'			:["{#$HAS_HOMEPAGE#}",3],
            'brand[]'			:["{#$HAS_BRAND#}",2],
            'question[]'		:["{#$HAS_QUESTION#}",2],
            'interest[]'		:["{#$HAS_INTEREST#}",2],
            'avatar2'			:["{#$HAS_INVITE_PIC#}",3]

        };
        var ck_ok =1;
        $.each(ck,function(i,n){
            switch(n[1]){
                case 1:

                    var o = $('#'+i);


                    if(o.val()==0){
                        //alert(n[0]);
                        ck_ok = 0;
                        o.focus();
                        $('#'+i+'_err').show();
                        return false;
                    }
                    break;
                case 2:
                    if(!check_checkbox(i)){
                        //alert(n[0]);
                        ck_ok = 0;
                        $('[name="'+i+'"]').eq(0).focus();

                        var l=i.length;
                        $('#'+i.substr(0,l-2)+'_err').show();
                        return false;
                    }
                    break;
                case 3:
                    var o = $('#'+i);
                    if($.trim(o.val()).length==0){
                        //alert(n[0]);
                        ck_ok = 0;
                        o.focus();
                        $('#'+i+'_err').show();
                        return false;
                    }
                    break;
            }
        });

        if(check_cssby('password') != 1){
            $('#password').focus();
            ck_ok = 0;
            return false;
        }else if(check_cssby('cpassword') != 1){
            $('#cpassword').focus();
            ck_ok = 0;
            return false;
        }else if(check_cssby('email') != 1){
            var re = check_register_email();

            if(re==0){
                $('#email').focus();
                ck_ok = 0;
                return false;
            }
        }else if(check_cssby('ename') != 1){
            $('#ename').focus();
            ck_ok = 0;
            check_register_ename()
            return false;
        }else if(check_cssby('phone') != 1){
            var re = check_register_phone();
            if(re==0){
                $('#phone').focus();
                ck_ok = 0;
                return false;
            }

            return false;
        }else if(check_cssby('idcard') != 1){
            $('#idcard').focus();
            ck_ok = 0;
            check_register_idcard()
            return false;
        }else if(check_cssby('birthday') != 1){
            $('#birthday').focus();
            ck_ok = 0;
            return false;
        }

        if(ck_ok){
            $("#register_form").submit();
        }
    }

    function formreset(){
        $('#register_form')[0].reset();
    }
</script>
<!--hidden-->
<div class="mbox" id="brand_form" style="visibility:hidden;top: 1380px;" >
    <a class="btn_close" href="###" onclick="selectcheckbox('brand_a','brand_form');"></a>
    <div class="hd">
        <h2 class="hd_title">請選擇您最喜愛的美容品牌</h2>
    </div>

    <div class="scrollBox">
        {#foreach from=$brand_key item=value key=key name=brand_key#}
        <div class="tit">
            {#$value#}<a href="###" class="few" onclick="toggle_brand_checkbox(this)"></a>
        </div>
        <dl>{#foreach from=$layout['brand'][$value] item=value1 key=key1#}
            <dd>
                <input value="{#$key1#}" type="checkbox" name="brand[]"  {#if in_array($key1,$layout.member.brand)#}checked="checked"{#/if#} brand_name="{#$value1#}" brand_name="Aesop">
                       {#$value1#}
            </dd>
            {#/foreach#}
        </dl>
        {#/foreach#}<div class="tit"><a href="#" class="few" onclick="toggle_brand_checkbox(this)">其他</a></div>
        <dl>
            {#foreach from=$SITE_LOOKUP['brand_arr']['其他'] item=value1 key=key1#}
            <dd><input value="{#$key1#}" type="checkbox" name="brand[]"  {#if in_array($key1,$layout.member.brand)#}checked="checked"{#/if#}   brand_name="{#$value1#}">{#$value1#}</dd>
            {#/foreach#}
        </dl>
    </div>
    <div class="ft">
        <a class="btn_s btn_s_p_submit" href="###" onclick="selectcheckbox('brand_a','brand_form');">
            <strong>提交</strong>
        </a>
        <a class="btn_s btn_s_p_clear" href="###" onclick="reset_brand_checkbox('brand[]')">
            <strong>清空</strong>
        </a>
    </div>


</div>
{#include file="footer.php"#}